package offer.system;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import system.bean.Member;
import system.dao.MemberDao;
import util.PageList;

public class GetMemberSource {
	private static MemberDao memberDao = new MemberDao();
	
	public static ArrayList<Object> getList(int memberId){
		 ArrayList<Object> list = null;
		 
		 
		 return list;
	}
	
	public static ArrayList<Object> getPageList(HttpServletRequest request , PageList pageBean)throws ServletException, IOException{
		if(null == pageBean) return null;
		ArrayList<Object> memberList = null;
		String lift_condition = "";
		String search_key = request.getParameter("search_key");
		if(null != search_key){
			lift_condition = " and (real_name like '%"+search_key+"%' or empNo like '%"+search_key+"') ";
		}
		String isPaging = request.getParameter("isPaging");
		int totalItems = 0;
		if(isPaging!=null&&isPaging.equalsIgnoreCase("Y")){
	    	int iPageNo = Integer.valueOf(request.getParameter("iPageNo"));
	    	totalItems = Integer.valueOf(request.getParameter("totalItem"));
	    	pageBean.setCurrentPage(iPageNo);
	    	pageBean.setTotalItems(totalItems);
	    	pageBean.setPageSize(2);
	    }else{
	    	totalItems = memberDao.getTotalMembers(lift_condition);
	    	pageBean.setCurrentPage(1);
	    	pageBean.setTotalItems(totalItems);
	    	pageBean.setPageSize(2);
	    }
		pageBean.CalculatePageNoInfo();
		String sql = "select memberId,real_name,email,empNo from "+Member.tableName+" where 1=1 "+lift_condition+
		" limit "+pageBean.getStart()+", "+pageBean.getPageSize();
		String exception = "GetMemberSource : getPageList has error!";
		memberList = memberDao.getList(sql, exception);
		return memberList;
	}
	
	public static Member getMemberById(int memberId){
		return memberDao.getMemberByMemberId(memberId);
	}
	
}
